<?php 
class Student { 
private $surname; 
private $first_name; 
private $emails; 
private $status;
private $grades; 
function __construct($surname, $first_name) 
{ 
$this->surname = $surname; 
$this->first_name = $first_name; 
$this->emails = array(); 
$this->grades = array(); 
$this->status = '';
    } 
    function add_email($which, $address) 
    { 
        $this->emails[$which] = $address; 
    } 
    function add_grade($grade) 
    { 
        $this->grades[] = $grade; 
    }
    function set_status($status) 
    { 
        $this->status = $status; 
    }
    function average() 
    { 
        $total = 0; 
        foreach ($this->grades as $value) 
            $total += $value; 
        return $total / count($this->grades); 
    }
    function toString() 
    { 
        $result = $this->first_name . ' ' . $this->surname . ' (' . $this->average() . ') ' . $this->status . "\n"; // Display the status next to the name and average
        foreach ($this->emails as $which => $what) 
            $result .= $which . ': ' . $what . "\n"; 
        $result .= "\n"; 
        return '<pre>' . $result . '</pre>'; 
    }

}
